package com.core.MQ;

import com.core.service.email.NotificationService;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import java.util.Map;

@Component
@Profile("mq-rocket") // 关键
@RocketMQMessageListener(
        topic = "RESERVATION_TOPIC", // 假设RocketMQ用这个topic
        consumerGroup = "email-consumer-group",
        selectorExpression = "success" // 对应我们之前说的tag
)
@RequiredArgsConstructor
public class RocketMQConsumer implements RocketMQListener<Map<String, Object>> {

    private final NotificationService notificationService;

    @Override
    public void onMessage(Map<String, Object> payload) {
        // 注意：如果RocketMQ的生产者发送时 topic 是 "RESERVATION_TOPIC:success"，
        // 这里的 topic 和 selectorExpression 配置就能正确匹配。
        // 为了和 RabbitMQ 的 topic "reservation.success" 对齐，
        // 在 RocketMQProducerImpl 中发送时，应该使用 "RESERVATION_TOPIC:success" 作为 destination。
        notificationService.processReservationSuccessNotification(payload);
    }
}